/**
 * @param {number[][]} triangle
 * @return {number}
 * @description 参考答案
 */

var minimumTotal = function (triangle) {
    const n = triangle.length
    for (let i = 1; i < n; i++) {
        for (let j = 0; j <= i; j++) {
            if (j === 0) {
                triangle[i][j] += triangle[i - 1][j]
            } else if (j === i) {
                triangle[i][j] += triangle[i - 1][j - 1]
            } else {
                triangle[i][j] += Math.min(triangle[i - 1][j], triangle[i - 1][j - 1])
            }
        }
    }
    return Math.min(...triangle[n - 1])
};
minimumTotal([[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]])